package com.he.algorithm.dynamic;

/**
 * @description: TODO
 * @Author: HCL
 * @Date: 2024/8/27 9:36
 */
public class FacUtil {

    public static int simpleFac(int n) {
        System.out.println("n = " + n);
        return n > 0 ? n * simpleFac(n - 1) : 1;
    }

    /**
    * @Description 动态规划
    * @Author HCL
    * @Date 2024/8/27 9:51
    * @Param [n]
    * @Return int
    */
    public static int dynamicFac(int n) {
        int[] nums = new int[n + 1];
        nums[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            // 状态转移方程
            nums[i] = i * nums[i - 1];
            System.out.println("i = " + i);
            System.out.println("nums[i] = " + nums[i]);
        }
        return nums[n];
    }

    public static void main(String[] args) {
//        System.out.println(simpleFac(3));
        System.out.println(dynamicFac(3));
    }
}
